using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
//using ShivamEMR.Web.Areas.Company.Models;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class BranchGroupController : Controller
    {
		private readonly ICompanyRepository companyRepository;
		private readonly IBranchGroupRepository branchgroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public BranchGroupController()
        {
            companyRepository = Registry.RepositoryFactory.GetCompanyRepository();
            branchgroupRepository = Registry.RepositoryFactory.GetBranchGroupRepository();
        }

        public BranchGroupController(ICompanyRepository companyRepository, IBranchGroupRepository branchgroupRepository)
        {
			this.companyRepository = companyRepository;
			this.branchgroupRepository = branchgroupRepository;
        }

        //
        // GET: /BranchGroup/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
           // return View(branchgroupRepository.AllIncluding(branchgroup => branchgroup.Company, branchgroup => branchgroup.Branches));
            return View(branchgroupRepository.All);
        }

        //
        // GET: /BranchGroup/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(branchgroupRepository.Find(id));
        }

        //
        // GET: /BranchGroup/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
			ViewBag.PossibleCompanies = companyRepository.All;
            return View();
        } 

        //
        // POST: /BranchGroup/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(BranchGroup branchgroup)
        {
            if (ModelState.IsValid) {
                branchgroupRepository.Create(branchgroup);
                branchgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCompanies = companyRepository.All;
				return View();
			}
        }
        
        //
        // GET: /BranchGroup/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleCompanies = companyRepository.All;
             return View(branchgroupRepository.Find(id));
        }

        //
        // POST: /BranchGroup/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(BranchGroup branchgroup)
        {
            if (ModelState.IsValid) {
                branchgroupRepository.Update(branchgroup);
                branchgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleCompanies = companyRepository.All;
				return View();
			}
        }

        //
        // GET: /BranchGroup/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(branchgroupRepository.Find(id));
        }

        //
        // POST: /BranchGroup/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            //branchgroupRepository.Delete(id);
            var bgroup = branchgroupRepository.Find(id);
            branchgroupRepository.Delete(bgroup);
            branchgroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

